home *** CD-ROM | disk | FTP | other *** search
/ Mac Expert 1995 Winter / Mac Expert - Winter 95.iso / Les fichiers / Communications / Divers / DinkClass ƒ / DinkClass / DWindow.c < prev    next >
Encoding:
Text File  |  1992-12-31  |  6.8 KB  |  367 lines  |  [TEXT/KAHL]

  1. /*
  2.     File:        DWindow.cp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Written by:    Mark Gross
  7.  
  8.     Copyright:    © 1992 by Applied Technical Software, all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <6>    12/31/92    MTG        making the code conditionaly compiled so         that I am
  13.                                     always working with a current         version in either think c
  14.                                     or MPW C++
  15.          <5>    11/14/92    MTG        Bringing the C++ version up to date WRT the ThinkC version.
  16.          <4>     9/20/92    MTG        Bringing the C++ code up to date with the THINK C version
  17.          <3>      8/9/92    MTG        merging changes from the ThinkC version
  18.          <2>      8/8/92    MTG        clearing up un-used variables
  19.  
  20.     To Do:
  21. */
  22.  
  23. // the is the Class definition for the DWindow class
  24.  
  25.  
  26. #include "DWindow.h"
  27. #include "DDocument.h"
  28. #include "DEventHandler.h"
  29. #include <DinkUtils.h>
  30.  
  31. DWindow::DWindow(void)
  32. {
  33.     //stub!!
  34. }
  35.  
  36.  
  37. DWindow::~DWindow(void)
  38. {
  39.     DisposHandle( (Handle) fPrintRecord);
  40. }
  41.     
  42.     
  43. Boolean DWindow::Init(DDocument *doc, Boolean hasColorWindows)
  44. {
  45.     WindowPtr prevFrontWindow;
  46.     Point corner;
  47.     RgnHandle    theGrayRgn;
  48.     Rect r;
  49.  
  50.     SetRect(&r, 0,0,0,0);
  51.     
  52.     fVOffSet = 0;
  53.     fHOffSet = 0;
  54.  
  55.     theGrayRgn = GetGrayRgn();
  56.     fGrowWindowLimits = (**theGrayRgn).rgnBBox;
  57.     fGrowWindowLimits.top = MINHIGHT; 
  58.     fGrowWindowLimits.left = MINWIDTH;
  59.     
  60.     fPrintRecord = (THPrint) NewHandle(sizeof(TPrint) );
  61.         //set up the print record with the last printer settings
  62.     if(fPrintRecord != NULL)
  63.     {
  64.         PrOpen();
  65.         PrintDefault(fPrintRecord);
  66.         PrClose();
  67.     }
  68.  
  69.     prevFrontWindow =  FrontWindow();
  70.     if(prevFrontWindow != NULL)
  71.     {
  72.         SetPort( prevFrontWindow);
  73.         corner.v = prevFrontWindow->portRect.top;
  74.         corner.h = prevFrontWindow->portRect.left;
  75.         LocalToGlobal(&corner);
  76.     }    
  77.     
  78.     fDoc = doc;
  79.     
  80.     if(hasColorWindows)
  81.         fWindowPtr = GetNewCWindow(rWindowID, NULL, (WindowPtr)-1L);
  82.     else
  83.         fWindowPtr = GetNewWindow(rWindowID, NULL, (WindowPtr)-1L);
  84.     
  85.     if(fWindowPtr)
  86.     {
  87.         fNextHandler = fDoc;
  88.         SetWRefCon(fWindowPtr, (long)this);    // tie this to window for activate events!!
  89.         if(prevFrontWindow != NULL)
  90.             MoveWindow(fWindowPtr, corner.h + kStagger, corner.v + kStagger, TRUE);
  91.         ShowWindow(fWindowPtr);
  92.  
  93.         return TRUE;
  94.     }
  95.     else
  96.     {
  97.         KillMeNext();
  98.         return FALSE;
  99.     }
  100.         
  101. }// end of Init member function
  102.     
  103.  
  104.  
  105.  
  106. void DWindow::Draw( Rect *area)
  107. {
  108. #ifdef THINK_C
  109.     FillRect( area, dkGray);
  110. #else
  111.     FillRect( area, &qd.dkGray);
  112. #endif
  113.         // This lets you know that you forgot a 
  114.         // virtual override of this guy....
  115. }
  116.  
  117.  
  118.  
  119. void DWindow::HandleUpdateEvt(EventRecord *theEvent)
  120. {
  121.     SetPort (fWindowPtr);
  122.     BeginUpdate (fWindowPtr);
  123.     if( !EmptyRgn(fWindowPtr->visRgn) )
  124.         Draw( &(fWindowPtr->portRect));
  125.     DrawGrowIcon( fWindowPtr);
  126.     EndUpdate(fWindowPtr);
  127.     
  128.     inherited::HandleUpdateEvt(theEvent);
  129. }
  130.  
  131.     
  132. void DWindow::HandleActivateEvt(EventRecord *theEvent)
  133. {
  134.     FocusOnContent();
  135.     if( !EmptyRgn(fWindowPtr->visRgn) )
  136.         Draw( &(fWindowPtr->portRect));
  137.     DrawGrowIcon(fWindowPtr);
  138.     
  139.     inherited::HandleActivateEvt(theEvent);
  140. }
  141.  
  142.     
  143. Boolean DWindow::KillMeNext(void)
  144. {
  145.     Boolean inheritedSuccess = FALSE;
  146.  
  147.     if(fAlive && fDoc->WindowClosed(this))// to give the user a chance to back out of the close...
  148.     {
  149.         if (inheritedSuccess = inherited::KillMeNext() )
  150.         {
  151.             
  152.             //
  153.             // These have to be after the inherited call
  154.             // to avoid getting stuck in a recursive
  155.             // stack smashing mess.  I'm looking for a better way.
  156.             //
  157.             
  158.             DisposeWindow( fWindowPtr );
  159.         }
  160.     }
  161.     return inheritedSuccess;
  162. }
  163.  
  164. void DWindow::HandleMouseDown(EventRecord *theEvent, short thePart, WindowPtr theWindow)
  165. {
  166.     if (theWindow == fWindowPtr)
  167.     {
  168.         switch( thePart)
  169.         {
  170.             case     inGoAway:
  171.                 if (TrackGoAway(theWindow, theEvent->where) )
  172.                     KillMeNext();
  173.                 break;
  174.             
  175.             case    inDrag:
  176.                     DoDrag(theEvent);
  177.                 break;
  178.             
  179.             case    inGrow:
  180.                     DoGrow(theEvent);
  181.                 break;
  182.             
  183.             case    inZoomIn:
  184.             case    inZoomOut:
  185.                 if( TrackBox( theWindow, theEvent->where, thePart) ) 
  186.                     DoZoom(thePart);
  187.                 break;
  188.             
  189.             case    inContent:
  190.                 DoContent(theEvent);
  191.                 break;
  192.         }// end switch
  193.     }
  194.     else
  195.         ; // do nothing but pass it on
  196.     
  197.     inherited::HandleMouseDown(theEvent, thePart, theWindow);
  198. }
  199.  
  200.  
  201. void DWindow::DoDrag(EventRecord *theEvent)
  202. {
  203.     RgnHandle    theGrayRgn;
  204.     Rect        r;
  205.     
  206.     theGrayRgn = GetGrayRgn();
  207.     r = (**theGrayRgn).rgnBBox;
  208.     
  209.     DragWindow(fWindowPtr, theEvent->where, &r);
  210.  
  211. }// end member function DoDrag
  212.  
  213.  
  214. void DWindow::DoGrow(EventRecord *theEvent)
  215. {
  216.     long        result;
  217.     RgnHandle    theGrayRgn;
  218.     Rect        r;
  219.     
  220.     theGrayRgn = GetGrayRgn();
  221.     r = (**theGrayRgn).rgnBBox;
  222.     r.top = MINHIGHT; r.left = MINWIDTH;
  223.     r = fGrowWindowLimits;
  224.     SetPort(fWindowPtr);
  225.     result = GrowWindow(fWindowPtr, theEvent->where, &r);
  226.     
  227.     if(result != 0)
  228.     {
  229.         r = fWindowPtr->portRect;
  230.         r.left = r.right - kScrollBarPos;
  231.         InvalRect(&r);
  232.         EraseRect(&r);
  233.         r = fWindowPtr->portRect;
  234.         r.top = r.bottom - kScrollBarPos;
  235.         InvalRect(&r);
  236.         EraseRect(&r);
  237.         
  238.         SizeWindow(fWindowPtr, LoWrd(result), HiWrd(result), TRUE);
  239.         
  240.         r = fWindowPtr->portRect;
  241.         r.left = r.right - kScrollBarPos;
  242.         InvalRect(&r);
  243.         EraseRect(&r);
  244.         r = fWindowPtr->portRect;
  245.         r.top = r.bottom - kScrollBarPos;
  246.         InvalRect(&r);
  247.         EraseRect(&r);
  248.     }// end if 
  249. }// end of member function DoGrow
  250.  
  251.  
  252. void DWindow::DoZoom(short thePart)
  253. {    
  254.     SetPort(fWindowPtr);
  255.     EraseRect(&fWindowPtr->portRect);
  256.     ZoomWindow(fWindowPtr, thePart, fWindowPtr == FrontWindow());
  257.     
  258.     InvalRect(&fWindowPtr->portRect);
  259. }// end member function DoZoom
  260.     
  261.  
  262. void DWindow::DoContent(EventRecord *theEvent)
  263. {
  264.  
  265.     ; // stub!!
  266.  
  267. }// end member function DoContent
  268.  
  269.  
  270.  
  271. void    DWindow::DoPageSetUp(void)
  272. {
  273.     PrOpen();
  274.     (void)PrStlDialog(fPrintRecord);
  275.     PrClose();
  276. }
  277.  
  278.  
  279. void    DWindow::DoPrint(void)
  280. {
  281.     TPPrPort    printPort;
  282.     Rect        r;
  283.     TPrStatus    status;
  284.     THPrint        tmpPrintRecord;
  285.     
  286.     tmpPrintRecord = fPrintRecord;
  287.     PrOpen();
  288.     if (PrValidate(tmpPrintRecord) )
  289.         if (!PrStlDialog(tmpPrintRecord) )
  290.         {
  291.             PrClose();
  292.             return;
  293.         }
  294.         
  295.     if (!PrJobDialog(tmpPrintRecord) )
  296.     {
  297.         PrClose();
  298.         return;
  299.     }
  300.     
  301.     printPort = PrOpenDoc(tmpPrintRecord, NULL, NULL);
  302.     
  303.     PrOpenPage(printPort, NULL);
  304.     
  305.     SetRect(&r, 0, 0, 0, 0);
  306.     Draw(&r);
  307.     
  308.     PrClosePage(printPort);
  309.     
  310.     PrCloseDoc(printPort);
  311.     
  312.     if ((**tmpPrintRecord).prJob.bJDocLoop != 0)
  313.         PrPicFile(tmpPrintRecord, NULL, NULL, NULL, &status);
  314.         
  315.     PrClose();
  316.     // now clean up the mess we made on the screen!!!
  317.     
  318.     FocusOnWindow();
  319.     InvalRgn( ((WindowPeek)fWindowPtr)->contRgn);
  320. }
  321.  
  322.  
  323. void DWindow::SetWindowTitle(void)
  324. {
  325.     StringPtr title;
  326.     
  327.     if(fDoc->fFileRef != 0) //fFileRef is the file open flag.
  328.     {
  329.         title = (fDoc->fFileReply->sfFile).name;
  330.         SetWTitle(fWindowPtr, title);
  331.     }
  332. }
  333.  
  334. void    DWindow::FocusOnContent(void)
  335. {
  336.     Rect r;
  337.     
  338.     SetPort(fWindowPtr);
  339.     SetOrigin(fHOffSet, fVOffSet);
  340.     GetContentRect(&r);
  341.     ClipRect(&r);
  342. }/*end of function*/
  343.  
  344.  
  345. void    DWindow::FocusOnWindow(void)
  346. {
  347.     Rect r;
  348.     
  349.     SetPort(fWindowPtr);
  350.     SetOrigin(0,0);
  351.     r = fWindowPtr->portRect;
  352.     ClipRect(&r);
  353. }/*end of function*/
  354.     
  355.  
  356. void    DWindow::GetContentRect(Rect *r)
  357. {
  358.     *r = fWindowPtr->portRect;
  359.     r->right -= kScrollBarPos;
  360.     r->bottom -= kScrollBarPos;
  361. }/*end of function*/
  362.  
  363.     
  364.     
  365.     
  366.     
  367.